package com.net;

public class SameNum {

  public static void main(String[] args) throws InterruptedException {
    SameNumThread run = new SameNumThread();
    Thread t1 = new Thread(run);

    Thread t2 = new Thread(run);

    Thread t3 = new Thread(run);

    Thread t4 = new Thread(run);

    Thread t5 = new Thread(run);

    t1.start();

    t2.start();

    t3.start();

    t4.start();

    //isAlive判断当前线程是否处于活跃状态
    System.out.println("--t5 is active:" + t5.isAlive() + "\n");
    t5.start();
    //Thread.sleep(5000);
    System.out.println("==t5 is active:" + t5.isAlive() + "\n");

  }

}

class SameNumThread extends Thread {
  private int i = 5;

  @Override
  public void run() {

    //虽然println() 方法在内部是同步的, 但i--的操作却是在进入println()之前发生的,所以有发生非线程安全的概率
    System.out.println(" i="+(i--) +" threadName="+Thread.currentThread().getName());
  }
}
